<?php
if (realpath($system_path) !== FALSE)
{
	$system_path = realpath($system_path).'/';
}

// ensure there's a trailing slash
$system_path = rtrim($system_path, '/').'/';

//echo $system_path;

define('BASEPATH', str_replace("\\", "/", $system_path));
define('EXT','.php');

//ob_start();
//ob_implicit_flush(0);
session_start();
defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));
include_once ("config/config.php");
//die('asasa');
//global $DB;

//if(!isset($_GET['ip']))
	//exit('Not Ip address...');
//$ip	=	$_GET['ip'];
$ip	=	$_SERVER['REMOTE_ADDR'];

$phpsessid	 =	$_COOKIE['PHPSESSID'];
//echo $phpsessid;die('00000000');

$tmp	=	$DB->query("SELECT * FROM sso_sessions WHERE PHPSESSID='".$phpsessid."'");
$row = $DB->fetch_row($tmp);

$user	=	json_encode($row['items']);
$urlback	=	$_GET['url'];

//print_r($row);die();

if($row)
{
	echo "<script>window.opener.location.href='".$urlback.(strpos($urlback, '?') ? '&' : '?')."auth=1&user=$user';window.close();</script>";
}
else
{
	//echo "<script>window.close();</script>";
	echo "<script>window.opener.location.href='".$urlback.(strpos($urlback, '?') ? '&' : '?')."auth=1&user=$user';window.close();</script>";
}
//print_r($_COOKIE);

die(json_encode($row));